home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 010a / fdcrw100.zip / FDC-RW.ASM next >
Assembly Source File  |  1991-08-01  |  9KB  |  304 lines

  1.         name    TSR
  2.         page    60,132
  3.         title   FDC-RW.COM program -- Floppy Disk Controller Register Watch
  4. ;
  5. ;  I needed to test a program ... this will be my first attempt at a TSR
  6. ;
  7. ;       Jesse Monroy,   07-30-91
  8. ;
  9. ;       to assemble:    MASM fdc-rw.asm,,,,
  10. ;                       LINK fdc-rw;
  11. ;       ignore no stack warning
  12.  
  13. CR              equ     0dh
  14. LF              equ     0ah
  15. monoseg         equ     0b000h
  16. colorseg        equ     0b800h
  17. scrnpos         equ     008ch
  18. main_stat_reg   equ     03f4h
  19. digital_out_reg equ     03f2h      ; aka Drive control Register
  20. monomode        equ     07h
  21. intr_to_trap    equ     08h
  22. bits_to_shift   equ     08h
  23.  
  24. csegment        segment word public     'CODE'
  25.                 assume  cs:csegment, ds:csegment, es:csegment, ss:csegment
  26.  
  27.                 org 100h
  28. start_mycode:
  29.                 jmp     start_code
  30.  
  31. author          db      ' FDC  Register  Watch v1.0',cr,lf
  32.                 db      ' By  Newind  Inc.',cr,lf,lf,'$'
  33.  
  34. help_msg        db      '   Usage:regwatch [-options]',cr,lf
  35.                 db      '       options  are  :',cr,lf
  36.                 db      '          m  - force monochrome video',cr,lf
  37.                 db      '          c  - force color video',cr,lf
  38.                 db      '          r  - reset the FDC and run the watch',cr,lf
  39.                 db      '          R  - reset the FDC and exit',cr,lf
  40.                 db      '          n  - use non-resident mode',cr,lf
  41. cr_lf           db      cr,lf,'$'
  42.  
  43. LOAD_msg        db      '   Floppy Disk Controller - Register Watch'
  44.                 db      '  is loaded as a TSR!!',cr,lf,'$'
  45. mono_msg        db      '   Using MonoChrome Video.',cr,lf,'$'
  46. color_msg       db      '   Using Color Video.',cr,lf,'$'
  47. nonres_msg     db      '   Running in Non memory resident mode.',cr,lf,'$'
  48. reset_msg       db      '   FDC controller reset!',cr,lf,'$'
  49. reset_x_msg     db      '   Exiting without installing FDC Register Watch.',cr,lf,'$'
  50.  
  51. one_char        dw      '1',70h         ; '1'- one charecter in inverse attrib
  52. zero_char       dw      '0',07h         ; '0'- zero charecter in normal attrib
  53.  
  54. switches        db      0
  55. storage         db      0
  56.  
  57. vid_offset      dw      scrnpos
  58. vid_segment     dw      0
  59. vid_mode        db      0
  60.  
  61. old_int_pointer equ     this dword
  62. old_offset      dw      ?
  63. old_segment     dw      ?
  64.  
  65. TSR_code:
  66.         pushf
  67.          call cs:old_int_pointer       ; call original ISR
  68.          cli                           ; disable (close) system interrupts
  69.  
  70.          push es                       ; save registers
  71.          push si
  72.          push di
  73.          push ds
  74.          push ax
  75.          push cx
  76.          push dx
  77.  
  78.          push cs                        ; point ds to cs
  79.          pop  ds
  80.  
  81.          mov  dx, main_stat_reg
  82.          in   al, dx                    ;get value of read only register
  83.          mov  storage, al
  84.          sti                            ; set interrupt flag (start intr)
  85.  
  86.          mov  es,cs:vid_segment         ; establish correct video base address
  87.          mov  di, vid_offset            ; establish correct video offset
  88.          cld                            ; increment form left to right
  89.          mov  cx, bits_to_shift         ; number of bits to print
  90. next:
  91.          shl  al, 01                    ; shift bit to carry flag
  92.          jnc  no_bit
  93.  
  94.          mov  si, offset one_char
  95.          jmp  show
  96. no_bit:
  97.          mov  si, offset zero_char
  98. show:
  99.          movsb                          ; move character into slot.
  100.          inc  si                        ; explictly increment "si" -- bug fix
  101.          movsb                          ; move attrib into slot.
  102.          loop next
  103.  
  104.          pop  dx                        ;restore registers
  105.          pop  cx
  106.          pop  ax
  107.          pop  ds
  108.          pop  di
  109.          pop  si
  110.          pop  es
  111.          sti
  112.  
  113.          iret                           ;issue EOI
  114. TSR_code_end:
  115.  
  116. ;===============
  117. ;
  118. ;
  119.  
  120. start_code:
  121.         PUSH   CS                       ; point "ES" and "DS" to "CS"
  122.         PUSH   CS
  123.         POP    DS
  124.         POP    ES
  125.  
  126.         call   cmdline
  127.  
  128.         MOV    AH, 0fh
  129.         INT    10h                      ;Get current display mode
  130.  
  131.         mov    vid_mode, al
  132.  
  133.         test   switches, 04h            ; Reset the controller?
  134.         jz     jmp2
  135.         mov    dx, digital_out_reg
  136.         mov    al, 00
  137.         out    dx, al
  138. reset:                                 
  139.         mov     dx, offset reset_msg    ; "FDC controller reset
  140.         mov     ah, 09h
  141.         int     21h
  142.  
  143.         test   switches, 10h            ; exclusive Reset
  144.         jz     jmp2                     ; exit without TSR code
  145.  
  146.         mov     dx, offset reset_x_msg  ; "FDC controller reset
  147.         mov     ah, 09h
  148.         int     21h
  149.  
  150.         jmp    exxit                    ; may do an exclusive reset later
  151. jmp2:
  152.  
  153.         test   switches, 01h            ; check for forced monochrome mode
  154.         jnz    mono
  155.         test   switches, 02h            ; check for forced color video
  156.         jnz     color
  157.         CMP    vid_mode, monomode       ; check current video mode
  158.         jne    color
  159. mono:
  160.         MOV    cs:vid_segment, monoseg  ; load monochrome video segment
  161.         mov     dx, offset mono_msg
  162.         mov     ah, 09h
  163.         int     21h
  164.         jmp    jmp1
  165. color:
  166.         MOV    cs:vid_segment, colorseg ; load color video segment
  167.         mov     dx, offset color_msg
  168.         mov     ah, 09h
  169.         int     21h
  170. Jmp1:                       
  171.  
  172.         MOV    AH, 35h                  ;Get int vector
  173.         MOV    AL, intr_to_trap
  174.         INT    21h                      
  175.         MOV    WORD PTR old_offset, BX  ; save offset of intr
  176.         MOV    WORD PTR old_segment, ES ; save segment of int
  177.  
  178.         MOV    AH, 25h                  ; Set int vector
  179.         MOV    AL, intr_to_trap         ;   to
  180.         MOV    DX, offset TSR_code      ; our intr code
  181.         INT    21h                      
  182.  
  183.  
  184.         test    switches, 08h
  185.         jnz     nonres
  186.  
  187.         MOV    DX, offset LOAD_msg
  188.         MOV    AH, 09h
  189.         INT    21h                      ;"TSR Loaded!!"
  190.  
  191.         MOV    DX, offset TSR_code_end + 1
  192.         INT    27h                      ;Terminate/stay resident
  193.  
  194. nonres:
  195.         mov     dx, offset nonres_msg
  196.         mov     ah, 09h
  197.         int     21h
  198.  
  199.         mov     ah, 0ch                 ; clear keyboard buffer
  200.         mov     al, 08h                 ; and wait for a key stroke
  201.         int     21h
  202.  
  203.         cmp     al, 0                   ; look for extended keyboard
  204.         jne     uninstall
  205.  
  206.         mov     ah, 0bh                 ; get any extra keystrokes
  207.         int     21h
  208. uninstall:
  209.         push    ds
  210.         MOV     AH, 25h                 ; Set int vector
  211.         MOV     AL, intr_to_trap        ;   to
  212.         MOV     DX,old_offset           ; old intr code.
  213.         mov     ds,old_segment          ; wait till the last second to change
  214.                                         ; the "DS", otherwise other variables
  215.         INT     21h                     ; will be wrong
  216.         pop     ds
  217.  
  218.         jmp     exxit
  219.  
  220. exxit:
  221.         mov     ax, 4c00h
  222.         int     21h
  223.  
  224.  
  225. ;======================
  226. ;
  227. ;       subroutine
  228.  
  229. cmdline proc    near
  230.  
  231. jauthor:
  232.         mov     dx, offset author
  233.         mov     ah, 09h
  234.         int     21h
  235.  
  236.         mov     si, 0081h
  237.         cld
  238. jtop:
  239.         lodsb
  240.         CMP     AL, ' '                 ; space -- filter 'em out
  241.         JE      jtop
  242.         CMP     AL, 0dh                 ; 0Dh = Carrige Return
  243.         JE      go_jmp                  ; go to dummy jump spot
  244.         CMP     AL, '-'
  245.         JE      jcommand
  246.         CMP     AL, '/'
  247.         JE      jcommand
  248.         jmp     help_jmp
  249.  
  250. jcommand:
  251. ;        inc     si
  252.         lodsb
  253.         CMP     AL, 'R'
  254.         JE      jreset2
  255.         CMP     AL, 'r'
  256.         JE      jreset
  257.         CMP     AL, 'N'
  258.         JE      jnonres
  259.         CMP     AL, 'n'
  260.         JE      jnonres
  261.         CMP     AL, 'M'
  262.         JE      jmono
  263.         CMP     AL, 'm'
  264.         JE      jmono
  265.         CMP     AL, 'C'
  266.         JE      jcolor
  267.         CMP     AL, 'c'
  268.         JE      jcolor
  269.  
  270. help_jmp:
  271.         JMP    jhelp
  272. go_jmp:
  273.         jmp    jgo
  274.  
  275. jmono:
  276.         or      switches,01h            ; force monochrome mode
  277.         jmp     jtop
  278. jcolor:
  279.         or      switches,02h            ; force color mode
  280.         jmp     jtop
  281. jreset2:
  282.         or      switches,10h            ; exclusive reset (dont load the watch)
  283. jreset:
  284.         or      switches,04h            ; reset controler on start
  285.         jmp     jtop
  286. jnonres:
  287.         or      switches,08h            ; reset controler on start
  288.         jmp     jtop
  289.  
  290. jhelp:
  291.         mov     dx, offset help_msg
  292.         mov     ah, 09h
  293.         int     21h
  294. jexiterror:
  295.         mov     ax, 4c01h
  296.         int     21h
  297. jgo:
  298.         ret
  299.  
  300. cmdline endp
  301.  
  302. csegment ends
  303.          end start_mycode
  304.